<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script type="text/javascript">
    $(document).ready(function() {
        Page.render();
        Page.setStripeTable();

        var $btnSave = $('#btnSave');
        $btnSave.bind('click', function() {
            if (!confirm(PROMPT.confirm.restoreFactory)) return;

            var datas = null;
            SysUtil.showProgress(150, PROMPT.status.restoringFactory,
                function() {
                    return datas != null;
                },
                function() {
                    closeBox();
                    /*
                     if (!Page.isSupported(ItemUnsupportedTable.NOT_SUPPORT_PROMPT_REBOOT_WHEN_RESTORE_DEFAULT_CONFIGS, false)) {
                     AlertUtil.alertMsg(PROMPT.status.restoreFactorySuccess);
                     closeBox();
                     } else {
                     SysUtil.reboot({
                     rebootType: RENOOTTYPE.RESTORE_SETTING,
                     msg: PROMPT.status.restoreFactorySuccess,
                     callback: function(canceled) {
                     if (canceled) {
                     SysUtil.restoreRebootCancel();
                     } else {
                     location.reload();
                     }
                     closeBox();
                     }
                     });
                     }
                     */
                }
            );

            setTimeout(function() {
                    datas = {};
                    setTimeout(function(){
                        Page.postJSON({
                            $id: $btnSave,
                            json: {
                                cmd: RequestCmd.RESTORE_DEFAULT,
                                method: JSONMethod.POST
                            },
                            success: function(data) {
                                if(data.success == true){
                                    AlertUtil.alertMsg(PROMPT.status.restoreFactorySuccess);
                                    reboot();
                                }
                                else{
                                    AlertUtil.alertMsg(PROMPT.status.fail);
                                    location.reload();
                                }
                            }
                        });
                    },1000);
            }, 3000);


            function reboot(ip) {
                // 发送重启命令
                Page.postJSON({
                    json: {
                        cmd: RequestCmd.SYS_REBOOT,
                        method: JSONMethod.POST
                    },
                    success: function() {
                        var isOk = false;
                        var timeoutCtl = setTimeout(function() {
                            isOk = true;
                        }, 1000 * 90);
                        SysUtil.showProgress(ProgressTime.REBOOT, PROMPT.status.rebooting,
                            function() {
                                return isOk;
                            },
                            function() {
                                clearTimeout(timeoutCtl);
                                if(ip){
                                    window.location.href = window.location.href.replace(window.location.host, ip);
                                }else {
                                    location.reload();
                                }

                            }
                        );
                    },
                    fail: function() {

                    }
                });
            }
        });

    });
</script>

<div class="tab_box" id="child_container">
    <script type="text/template" id="child_template">
        <table class="detail" cellspacing="0">
            <tr>
                <th><%- sys.restoreFactory %><%- colon %></th>
                <td><input type="button" id="btnSave" value="<%- btn.restoreFactory %>"/></td>
            </tr>
        </table>
    </script>
</div>

